<?php get_header(); ?>
<?php 
    global $maps; 
    $url = plugins_url( 'manage-golf-club/include/upload/' ,'' );
?>
    <div id="main">
    	<div class="wrapper">
            <div class="maincontent">
                <?php $cats = get_the_category( $id ); ?>
                <?php if (function_exists('get_cat_icon')) get_cat_icon('cat='.$cats[0]->cat_ID); ?>
                
                <div class="breadcrumb">
                    <?php 
                        if(function_exists('bcn_display')){
                            bcn_display();
                        }
                    ?>
                </div>
                <h1><?php single_post_title('', true) ?></h1>
                <div class="detail-wrapper">
                    <?php 
                        global $post;
                        while(have_posts()):the_post(); 
                    ?>
                    <div class="image">
                        <?php 
                            if(has_post_thumbnail()) the_post_thumbnail();
                        ?>
                    </div>
                    <div class="detail">
                    	<div class="info-group">
                            <div class="info">
                                <?php the_content(); ?>
                            </div>
                            <?php if(!isset($_REQUEST['action'])){ ?>
                                <div class="link"><a href="<?php the_permalink() ?>?action=book">Book One Day Golf</a></div>
                            <?php }?>
            		</div>
                        <?php if(!isset($_REQUEST['action'])){ ?>
                        <div class="fac">
                            <?php if(get_field('facilities', $post->ID)){ ?>
                            <strong>Facilities</strong>
                            <ul>
                                <?php 
                                    $facilities = get_field('facilities', $post->ID); 
                                    for($i=0;$i<count($facilities);$i++){
                                        $facilities_class = str_replace(' ','-',strtolower($facilities[$i]));
                                        echo'<li class="fac-'.$facilities_class.'"><span title="'.$facilities[$i].'">'.$facilities[$i].'</span></li>';
                                    } 
                                ?>
                            </ul>
                            <?php } ?>
                        </div>
                        <?php if(get_field('about', $post->ID)){ ?>
                        <p><strong>About:</strong></p>
                        <div class="about-content">
                            <?php echo get_field('about', $post->ID); ?>
                        </div>
                        <?php } ?>
                        <?php }?>
                    </div>
                    <?php 
                        if(isset($_REQUEST['action']) && $_REQUEST['action']=='book'){
                            echo '<div class="clr"></div>
                            <div class="booking-form">'.do_shortcode('[booking_golf]').'</div>';
                        }
                    ?>
                    <?php if(!isset($_REQUEST['action'])){ ?>
                    <div id="tabs" class="tab-wrapper">
                            <ul class="tabs">
                                <li class="tab-1"><a href="#map-tab">Map</a></li>
                                <li class="tab-2"><a href="#score-card">Score Card</a></li>
                                <li class="tab-3"><a href="#gallery">Gallery</a></li>
                                <li class="tab-4"><a href="#events">Events</a></li>
                                <li class="tab-5"><a href="#accomodation">Accomodation</a></li>
                                <li class="tab-6"><a href="#after-golf">After Golf</a></li>
                            </ul>
                            <div id="map-tab" class="tab-content">
                                <h2>Map</h2>
                                <div class="document">
                                    <?php 
                                        $maps = $wpdb->get_row('SELECT * FROM algc_golf_club WHERE golf_club_id='.$post->ID.'');
                                        if(!empty($maps)){
                                            echo stripslashes($maps->map);
                                        }else echo'Map is not available';
                                    ?>
                                </div>
                            </div>
                            <div id="score-card" class="tab-content">
                                <h2>Score Card</h2>
                                <?php $scores = $wpdb->get_results('SELECT * FROM algc_score_card WHERE golf_club_id='.$post->ID.'') ?>
                                <?php 
                                    if(!empty($scores)){ 
                                        foreach($scores as $scoreItem){
                                ?>
                                <table cellpadding="0" cellspacing="0" width="100%" class="scorecard-tb">
                                    <thead>
                                        <tr>
                                            <th>Hole</th>
                                            <?php for($i=1;$i<21;$i++){
                                                if($i==10){
                                                    echo'<th>Out</th>';
                                                    $i=10;
                                                    echo'<th>'.$i.'</th>';
                                                }elseif($i==19){
                                                    echo'<th>In</th>';
                                                    $i=20;
                                                    echo'<th>Total</th>';
                                                }else echo'<th>'.$i.'</th>';
                                            }?>                                            
                                        </tr>
                                    </thead>
                                    <tbody>
                                       <tr class="black">    
                                           <td class="wide">Black&nbsp;</td>
                                           <?php 
                                                $black = explode(';',$scoreItem->black);
                                                for($i=0;$i<=20;$i++){
                                                    if($black[$i]==';') $black[$i] ='&nbsp;';
                                                    echo'<td>'.$black[$i].'&nbsp;</td>';
                                                }
                                           ?> 
                                       </tr>
                                       <tr class="blue">    
                                           <td class="wide">Blue&nbsp;</td>    
                                           <?php 
                                                $blue = explode(';',$scoreItem->blue);
                                                for($i=0;$i<=20;$i++){
                                                    if($blue[$i]==';') $blue[$i] ='&nbsp;';
                                                    echo'<td>'.$blue[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>
                                       <tr>    
                                           <td class="wide">White&nbsp;</td>    
                                           <?php 
                                                $white = explode(';',$scoreItem->white);
                                                for($i=0;$i<=20;$i++){
                                                    if($white[$i]==';') $white[$i] ='&nbsp;';
                                                    echo'<td>'.$white[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>
                                       <tr class="red">    
                                           <td class="wide">Red&nbsp;</td>    
                                           <?php 
                                                $red = explode(';',$scoreItem->red);
                                                for($i=0;$i<=20;$i++){
                                                    if($red[$i]==';') $red[$i] ='&nbsp;';
                                                    echo'<td>'.$red[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>
                                       <tr class="yellow"> 
                                           <td class="wide">Gold&nbsp;</td>
                                           <?php 
                                                $gold = explode(';',$scoreItem->gold);
                                                for($i=0;$i<=20;$i++){
                                                    if($gold[$i]==';') $gold[$i] ='&nbsp;';
                                                    echo'<td>'.$gold[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>
                                       <tr>    <td class="wide">&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td class="out">&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td class="in">&nbsp;</td>    <td class="total">&nbsp;</td>    <td>&nbsp;</td></tr>
                                       <tr>    
                                           <td class="wide">Index&nbsp;</td>
                                           <?php 
                                                $index = explode(';',$scoreItem->index);
                                                for($i=0;$i<=20;$i++){
                                                    if($index[$i]==';') $index[$i] ='&nbsp;';
                                                    echo'<td>'.$index[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>
                                       <tr>    
                                           <td class="wide">Par&nbsp;</td>
                                           <?php 
                                                $par = explode(';',$scoreItem->par);
                                                for($i=0;$i<=20;$i++){
                                                    if($par[$i]==';') $par[$i] ='&nbsp;';
                                                    echo'<td>'.$par[$i].'&nbsp;</td>';
                                                }
                                           ?>
                                       </tr>

                                    </tbody>
                                </table>
                                <?php }
                                }else echo 'Score card is not available';?>
                            </div>
                            <div id="gallery" class="tab-content">
                                <h2>Gallery</h2>
                                <ul class="gallery">
                                    <?php
                                      $gallery =   $wpdb->get_results('SELECT * FROM algc_golf_club_gallery WHERE golf_club_id='.$post->ID.'');
                                      if(empty($gallery)){
                                          echo 'No gallery here at the moment.';
                                      }else{
                                          foreach($gallery as $galleryItem){
                                    ?>
                                    <li><a href="<?php echo $url.$galleryItem->image ?>" class="img-zoom"><img src="<?php echo $url.$galleryItem->image ?>" alt="gallery" width="150px" height="100px" /></a></li>
                                    <?php } } ?>
                                </ul>
                            </div>
                            <div id="events" class="tab-content">
                                <h2>EVENTS</h2>
                                <div class="document">
                                    <?php
                                        $events = $wpdb->get_results('SELECT * FROM algc_golf_club_info WHERE golf_club_id='.$post->ID.' AND type="event"');
                                        if(empty($events)){
                                            echo 'No events here at the moment.';
                                        }else{
                                            echo '<ul class="list">';
                                            foreach($events as $event){
                                    ?>
                                            <li>
                                                <img src="<?php echo $url.$event->featured_image ?>" alt="image"/>
                                                <div class="description">
                                                    <p class="name"><strong><?php echo stripcslashes($event->title) ?></strong></p>  
                                                    <?php echo $event->content ?>
                                                </div>
                                            </li>
                                    <?php } 
                                        echo'</ul>';
                                    } ?>
                                </div>
                            </div>
                            <div id="accomodation" class="tab-content">
                                <h2>Accomodation</h2>
                                <?php
                                        $accomodations = $wpdb->get_results('SELECT * FROM algc_golf_club_info WHERE golf_club_id='.$post->ID.' AND type="accomodation"');
                                        if(empty($accomodations)){
                                            echo 'No accomodation here at the moment.';
                                        }else{
                                            echo '<ul class="list">';
                                            foreach($accomodations as $accomodation){
                                    ?>
                                            <li>
                                                <img src="<?php echo $url.$accomodation->featured_image ?>" alt="image"/>
                                                <div class="description">
                                                    <p class="name"><strong><?php echo stripcslashes($accomodation->title) ?></strong></p>  
                                                    <?php echo $accomodation->content ?>
                                                </div>
                                            </li>
                                    <?php } 
                                        echo'</ul>';
                                } ?>
                            </div>
                            <div id="after-golf" class="tab-content">
                                <h2>After Golf</h2>
                                <?php
                                        $after_golfs = $wpdb->get_results('SELECT * FROM algc_golf_club_info WHERE golf_club_id='.$post->ID.' AND type="after_golf"');
                                        if(empty($after_golfs)){
                                            echo 'No after golf here at the moment.';
                                        }else{
                                            echo '<ul class="list">';
                                            foreach($after_golfs as $after_golf){
                                    ?>
                                            <li>
                                                <img src="<?php echo $url.$after_golf->featured_image ?>" alt="image"/>
                                                <div class="description">
                                                    <p class="name"><strong><?php echo stripcslashes($after_golf->title) ?></strong></p>  
                                                    <?php echo $after_golf->content ?>
                                                </div>
                                            </li>
                                    <?php } 
                                        echo'</ul>';
                                } ?>
                            </div>
                        </div>
                        
                    <div class="social">
                        <!-- AddThis Button BEGIN -->
                            <div class="addthis_toolbox addthis_default_style ">
                                <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                                <a class="addthis_button_tweet"></a>
                            </div>
                            <script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>
                            <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4fba6377077bdaba"></script>
                        <!-- AddThis Button END -->
                    </div>
                    <?php } ?>
                    <?php endwhile; ?>
                </div>
            </div><!-- //maincontent -->
            <div class="aside">
                <?php include 'aside.php'; ?>
            </div>
            <div class="clr"></div>
            <div class="bg-main-bot"></div>
        </div><!-- //aside -->
    </div><!-- //main -->
<?php get_footer(); ?>
